//
//  TestViewController.m
//  JKOCRichText
//
//  Created by 王冲 on 2018/8/14.
//  Copyright © 2018年 希艾欧科技有限公司. All rights reserved.
//

#import "TestViewController.h"
#import "ViewController.h"
@interface TestViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;


@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor brownColor];
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.title = @"点赞的处理";
    
    [self.view addSubview:self.tableView];
    
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 10;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    if (!cell1) {
        
        cell1 = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
        cell1.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell1.backgroundColor = JKRandomColor;
    cell1.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
  
    return cell1;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JKWidth, 0.01)];
    sectionView.backgroundColor = backgrCOlor;
    return sectionView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JKWidth, 0)];
    sectionView.backgroundColor = [UIColor whiteColor];

    NSArray *goodArray = @[@"张三",@"李四",@"王五",@"李兆",@"粟子",@"小李",@"李四",@"王一五",@"李兆",@"粟子",@"小李"];
    
    NSMutableAttributedString *newGoodString = [JKwideHighSize attributedStringArray:goodArray withattributeFont:25.f withattributeTextColor:[UIColor redColor]];
    
    CGFloat height1 = [JKwideHighSize sizeLabelToFit:newGoodString width:JKWidth-40 height:MAXFLOAT].height;
    
    sectionView.height = height1+40;
    
    UILabel *goodTextLbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, self.view.bounds.size.width - 40, height1)];
    goodTextLbl.backgroundColor = [UIColor yellowColor];
    goodTextLbl.numberOfLines = 0;//设置UILable自适应
    goodTextLbl.attributedText = newGoodString;
    goodTextLbl.isShowTagEffect = NO;
    [sectionView addSubview:goodTextLbl];
    
    __weak typeof(self) weakSelf = self;
    [goodTextLbl onTapRangeActionWithString:goodArray tapClicked:^(NSString *string, NSRange range, NSInteger index)
    {
        //NSLog(@"这是第--%ld--个点赞的,他是--%@",index,string);
        [weakSelf clickLilkeIndepath:index withSection:section];
    }];
    
    return sectionView;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    NSArray *goodArray = @[@"张三",@"李四",@"王五",@"李兆",@"粟子",@"小李",@"李四",@"王一五",@"李兆",@"粟子",@"小李"];
    
    NSMutableAttributedString *newGoodString = [JKwideHighSize attributedStringArray:goodArray withattributeFont:25.f withattributeTextColor:[UIColor redColor]];
    
    CGFloat height1 = [JKwideHighSize sizeLabelToFit:newGoodString width:JKWidth-40 height:MAXFLOAT].height;
    
    return height1+40;
}


-(UITableView* )tableView{
    
    if (!_tableView) {
        
        // UITableViewStyleGrouped
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, JKWidth, JKHeight-64) style:UITableViewStyleGrouped];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor  = backgrCOlor;
    }
    return _tableView;
}

-(NSMutableArray *)dataArray{
    
    if (!_dataArray) {
        
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

#pragma mark 点赞的事件
-(void)clickLilkeIndepath:(NSInteger)index withSection:(NSInteger)section{
    
    NSLog(@"打印==第%ld段的第%ld个",section,index);

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        NSLog(@"%@", [NSThread currentThread]);
        ViewController *vc = [ViewController new];
        [self.navigationController pushViewController:vc animated:YES];
        
    });
}

@end


